package com.dstz.agilebpm.springcloud.auth.edge.rest;

import com.dstz.base.api.constant.BaseStatusCode;
import com.dstz.base.api.response.impl.ResultMsg;
import com.dstz.base.rest.GenericController;
import com.dstz.security.jwt.service.JWTService;
import lombok.extern.java.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * token校验器
 *
 * @author wacxhs
 */
@Log
@RestController
@RequestMapping("/auth/token")
public class TokenController extends GenericController {

    @Autowired
    private JWTService jWTService;


    /**
     * 校验token是否合法
     *
     * @return 接口处理结果
     */
    @GetMapping("validate")
    public ResultMsg<String> validate(@RequestParam("token") String token) {
        if (jWTService.getJwtEnabled()) {
            Boolean success = jWTService.validateToken(token);
            if (success) {
                return getSuccessResult();
            } else {
                return new ResultMsg<>(BaseStatusCode.PARAM_ILLEGAL, "token校验不通过");
            }
        } else {
            //TODO 传统方式实现
        }
        return getSuccessResult();
    }

}
